/*
Eteria IRC Client, an RFC 1459 compliant client program written in Java.
Copyright (C) 2001  Christian Buck <cbuck at lantis.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.awt.*;
import java.awt.event.*;

import ar.com.jkohen.awt.ImageButton;
import ar.com.jkohen.util.Resources;

public class TextAreaCopy extends Dialog implements ActionListener
{
	private EIRC eirc;
	private Frame frame;
    private TextArea ta;
	private Label label;

	private Resources res;

    public TextAreaCopy(EIRC eirc, Frame frame, String s)
	{
    	super(frame);
		this.eirc = eirc;
		this.frame = frame;

		setFont(eirc.getFont());

        GridBagLayout gb = new GridBagLayout();
    	GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);

        gbc.insets = new Insets(2, 2, 2, 2);

        ta = new TextArea(s);

        gbc.fill = GridBagConstraints.BOTH;
    	gbc.weighty = 1.0;
      	gbc.weightx = 1.0;
    	gb.setConstraints(ta, gbc);
    	add(ta);
      	gbc.weightx = 0.0;
    	gbc.weighty = 0.0;
        gbc.fill = GridBagConstraints.NONE;

    	gbc.gridy = 1;

    	Panel bottom_panel = new Panel();
    	GridBagLayout gb2 = new GridBagLayout();
    	GridBagConstraints gbc2 = new GridBagConstraints();
    	bottom_panel.setLayout(gb2);

    	gbc2.weightx = 1.0;
        gbc2.insets = new Insets(0, 2, 0, 2);

		label = new Label(res.getString("copy"));
		bottom_panel.add(label);
        ImageButton b = new ImageButton(res.getString("close"));
    	b.setActionCommand("ok");
        gb2.setConstraints(b, gbc2);
    	bottom_panel.add(b);
        b.addActionListener(this);
        b.setEnabled(true);

        gb.setConstraints(bottom_panel, gbc);
    	add(bottom_panel);

		setResizable(false);

		ta.selectAll();
		show();
    }

	public void setText(String s)
	{
		ta.setText(s);
		ta.selectAll();
	}

	public void setBackground(Color c)
    {
		super.setBackground(c);
		label.setBackground(c);
    }

	public void setForeground(Color c)
    {
		super.setForeground(c);
		label.setForeground(c);
    }

    public void setTextBackground(Color c)
    {
		ta.setBackground(c);
    }

    public void setTextForeground(Color c)
    {
		ta.setForeground(c);
    }

    public void setSelectedBackground(Color c)
    {
    }

    public void setSelectedForeground(Color c)
    {
    }

    public void actionPerformed(ActionEvent ev)
    {
		String ac = ev.getActionCommand();

		if (ac.equals("ok"))
			processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }

	public void show()
	{
		pack();
       	setLocation((frame.getSize().width - getSize().width) / 2 + frame.getLocation().x, (frame.getSize().height - getSize().height) / 2 + frame.getLocation().y);

		setBackground(eirc.getBackground());
		setForeground(eirc.getForeground());
		super.show();
	}
}
